package account.view;

import java.util.Random;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Window;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.GridBagLayout;

import javax.swing.JLabel;

import java.awt.GridBagConstraints;

import javax.swing.JTextField;

import java.awt.Insets;

import javax.swing.JButton;

import dao.account.DataLayerAccount;
import account.controller.MailController;
import account.model.Account;
import tools.mail.Mail;
import tools.mail.MailServer;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.sql.SQLException;

public class MailRecoveryView extends JPanel implements KeyListener {

	private static MailRecoveryView instance;
	private JFrame frame;
	private JTextField txtMail;
	private JLabel lblNewLabel;
	private JButton btnSend;
	private JLabel labeel;
	
	private JLabel warning;
	private String message;

	public static MailRecoveryView getInstance(){
		if (instance == null) {
			instance = new MailRecoveryView();
		}
		return instance;
	}
	
	public void run() {
		try {
			MailRecoveryView window = new MailRecoveryView();
			window.frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// runt methode die de frame aanmaakt
	public MailRecoveryView() {
		initialize();
	}

	//maakt de frame aan en zegt wat er in moet
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 254, 97);
		frame.setSize(350, 150);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 44, 36, 58, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		frame.getContentPane().setLayout(gridBagLayout);

	

		JLabel title = new JLabel("    ");
		frame.getContentPane().add(title);

		JLabel lblemail = new JLabel("*Emailadres");
		GridBagConstraints gbc_lblmail = new GridBagConstraints();
		gbc_lblmail.insets = new Insets(0, 0, 5, 5);
		gbc_lblmail.gridx = 2;
		gbc_lblmail.gridy = 1;
		frame.getContentPane().add(lblemail, gbc_lblmail);

		txtMail = new JTextField(20);
		txtMail.setText("kishanbakker@gmail.com");
		GridBagConstraints gbc_txtMail = new GridBagConstraints();
		gbc_txtMail.gridwidth = 3;
		gbc_txtMail.insets = new Insets(0, 0, 5, 0);
		gbc_txtMail.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtMail.gridx = 4;
		gbc_txtMail.gridy = 1;
		frame.getContentPane().add(txtMail, gbc_txtMail);
		txtMail.setColumns(10);

		btnSend = new JButton("Wachtwoord aanvragen");
		btnSend.addActionListener(new MailController());
		btnSend.setActionCommand("zoeken");


		GridBagConstraints gbc_btnSend = new GridBagConstraints();
		gbc_btnSend.insets = new Insets(0, 0, 0, 5);
		gbc_btnSend.gridx = 5;
		gbc_btnSend.gridy = 4;
		frame.getContentPane().add(btnSend, gbc_btnSend);
	}



	
	public JFrame getFrame() {
		return frame;
	}

	public void setFrame(JFrame frame) {
		this.frame = frame;
	}

	public String getTxtMail() {
		return txtMail.getText();
	}
	
	public void setTxtMail(JTextField txtMail) {
		this.txtMail = txtMail;
	}

	public JLabel getLblNewLabel() {
		return lblNewLabel;
	}

	public void setLblNewLabel(JLabel lblNewLabel) {
		this.lblNewLabel = lblNewLabel;
	}


	public JLabel getWarning() {
		return warning;
	}

	public void setWarning(JLabel warning) {
		this.warning = warning;
	}

	//maakt een foutmelding aan
	public void warn(String mess){
		warning = new JLabel(mess);
		warning.setForeground(Color.RED);
		GridBagConstraints gbc_warning = new GridBagConstraints();
		gbc_warning.insets = new Insets(0, 0, 5, 5);
		gbc_warning.gridx = 5;
		gbc_warning.gridy = 3;
		warning.setVisible(true);
		frame.getContentPane().add(warning, gbc_warning);
		frame.revalidate();
	}
	
	@Override
	public void keyPressed(KeyEvent arg0) {
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
	}
}
